package com.gz.logistics.adapter;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gz.logistics.R;
import com.gz.logistics.app.ClothesDetailActivity;
import com.gz.logistics.app.MainActivity;
import com.gz.logistics.library.IOrder;
import com.gz.logistics.library.pojo.ClothesDetails;

import org.w3c.dom.Text;

import java.util.List;

/**
 * author wanner1991
 * 衣物详情适配器
 */
public class ClothesDetailsAdapter extends BaseAdapter {
    private static  final String TAG = ClothesDetailsAdapter.class.getSimpleName();
    private List<ClothesDetails> mDataList;
    private Context mContext;
    private Dialog mMenudialog;
    private TextView mTvTitle;
    private RelativeLayout btn_ok;
    public ClothesDetailsAdapter(List<ClothesDetails> mDataList, Context mContext) {
        this.mDataList = mDataList;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mDataList.size();
    }

    @Override
    public Object getItem(int i) {
        return mDataList.get(i);
    }

    @Override
    public long getItemId(int i) {

        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null){
            view = LayoutInflater.from(mContext).inflate(R.layout.activity_clothes_detail,null);
            holder = new ViewHolder();
            holder.tv_brand = (TextView) view.findViewById(R.id.tv_brand);
            holder.tv_color = (TextView) view.findViewById(R.id.tv_color);
            holder.tv_money = (TextView) view.findViewById(R.id.tv_money);
            holder.tv_name = (TextView) view.findViewById(R.id.tv_name);
            holder.tv_special = (TextView) view.findViewById(R.id.tv_special);
            holder.tv_delete = (TextView) view.findViewById(R.id.tv_delete);
            holder.delete = (RelativeLayout) view.findViewById(R.id.delete);
            view.setTag(holder);
        }else {
            holder = (ViewHolder) view.getTag();
        }
        ClothesDetails detail = mDataList.get(i);
        holder.tv_brand.setText(detail.getBrand());
        holder.tv_color.setText(detail.getColour());
        holder.tv_money.setText(detail.getMoney()+detail.getAddtionalmoney()+"");
        holder.tv_name.setText(detail.getClothesname());
        holder.tv_special.setText(detail.getAddtionalequire());
        holder.tv_delete.setText("删除");

        /**
         * 点击删除，删除相应的衣物信息
         */
        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        return view;
    }
    private class ViewHolder{
        TextView tv_brand;
        TextView tv_color;
        TextView tv_money;
        TextView tv_name;
        TextView tv_special;//特殊处理
        TextView tv_delete;//取消按钮
        RelativeLayout delete;
    }
    public void createDialog() {
        mMenudialog = new Dialog(ClothesDetailActivity.context, R.style.DialogTheme);
        View dialogView = LayoutInflater.from(MainActivity.context).inflate(R.layout.mycommunity_dialog_layout, null);
        mTvTitle = (TextView) dialogView.findViewById(R.id.tv_title);
        mTvTitle.setText("删除衣物：");
        final EditText edittext = (EditText) dialogView.findViewById(R.id.money);
        edittext.setVisibility(View.GONE);
        btn_ok = (RelativeLayout) dialogView.findViewById(R.id.btn_ok);
        btn_ok.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
              /*  show_tv.setText("提交中...");
                mLoadingData.show();
                IOrder.getInstance().PostReceipt(user_type,order_num, edittext.getText().toString().trim(), postmoneyListener);*/
                mMenudialog.dismiss();
            }
        });
        dialogView.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                mMenudialog.dismiss();
            }
        });
        mMenudialog.setContentView(dialogView);
        mMenudialog.setCancelable(false);
        mMenudialog.setCanceledOnTouchOutside(false);
        mMenudialog.show();
    }
}
